$(function() {
	$("#left").load("../common/gover-left.html");
	$("#regDate").mobiscroll({preset : 'date', dateFormat: 'yy-mm-dd'});
	var businessId = parseQueryString().businessId;
	var type = parseQueryString().type ;
	var userType = parseQueryString().userType == null ? 'gr' : parseQueryString().userType;
	var code = parseQueryString().code;
	var userId = sessionStorage.getItem("userId");
	
	$(".ystep1").loadStep({
		size: "small",
		color: "green",
		steps: [{
				title: "事项选择"
			},
			{
				title: "服务选择"
			},
			{
				title: "信息录入"
			},
			{
				title: "寄件选择"
			},
			{
				title: "取件选择"
			},
			{
				title: "提交成功"
			}
		]
	});
	$(".ystep1").setStep(3);

	$(".form_horizontal .input_text").focus(function() {
		$(this).closest(".form-item").addClass("active")
	});
	$(".form_horizontal .input_text").blur(function() {
		$(this).closest(".form-item").removeClass("active")
	});

	$(":radio[name='rtype2']").click(function() {
		if($(this).attr("id") == "rtype2_1") {
			$("#sfz").show();
			$("#zhengjian").hide();
		} else {
			$("#sfz").hide();
			$("#zhengjian").show();
		}
	});
	my_vue = new Vue({
		el: '#vue_info',
		data: {
			itemsList: [],
			type: type,
			userId: userId,
			address: "",
			applyId: "",
			cardNum: "",
			contactName: "",
			mobile: "",
			businessId: businessId,
			itemsId: code,
			name: "",
			userType: userType,
			regNumber: "",
			regAddress: "",
			companyName: "",
			regDate: "",
			regCapital: "",
			companyTel: ""
		},
		methods: {
			exitProcess: function(op) {
				if(op == 'index') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toIndex
					});
				} else if(op == 'scanner') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toScanner
					});
				}
			},
			turnToFace2Face: function() {
				$.showConfirm({
					'title': '',
					'content': '是否确认进行面对面办证？',
					"showClose": false,
					"sureLabel": "取消",
					"cancelLabel": "确定",
					'cancel': this.toFace2Face
				});
			},
			toIndex: function() {
				window.location = "index.html"
			},
			toScanner: function() {
				window.location = "scannerIndex.html"
			},
			toFace2Face: function() {
				window.location = "face2faceWaiting.html"
			},
			toReturn: function() {
				window.location = "readIdentityCard.html";
			},

			lastStep: function() {
				if(isEmpty(businessId)){
					window.location = "selfHelpBusinessChoose.html?type="+type;
				}else{
					window.location = "selfHelpBusinessChooseList.html?type="+type+"&businessId="+businessId;
				}
			},
			exitAttendTo: function() {
				$.openDialog({
					'title': '',
					"showClose": false,
					'width': 824,
					'height': 460,
					'url': 'selfHelpExitChoose.html'
				});
			},
			getApplyInfo: function() {
				this.$http.get(gover.getApplyInfo+"?t="+new Date().getSeconds(), {
					userId: userId,
					itemsId: code,
					businessId: businessId,
					type: userType
				}).then(function(result) {
					doMask();
					if(result.data.success) {
						unMask();
						console.log(toJson(result.data.data));
						this.itemsList = result.data.data;
						this.address = result.data.data.address,
							this.regNumber = result.data.data.regNumber,
							this.regAddress = result.data.data.regAddress,
							this.companyName = result.data.data.companyName,
							this.regDate = result.data.data.regDate,
							this.regCapital = result.data.data.regCapital,
							this.companyTel = result.data.data.companyTel,
							this.applyId = result.data.data.applyId,
							this.cardNum = result.data.data.cardNum,
							this.cardType = result.data.data.cardType,
							this.contactName = result.data.data.contactName,
							this.mobile = result.data.data.mobile,
							this.userType = result.data.data.userType,
							this.name = result.data.data.name
						this.itemsId = result.data.data.itemsId

					}else{
						unMask();
						showRedMsg("message", "服务器正忙,请稍候重试");
					}
					console.log(toJson(result.data));

				}, function(result) {
					unMask();
					console.log('保存接口失败:' + toJson(result));
					showRedMsg("message", "服务器正忙,请稍候重试");

				})
			},
			saveApplyInfo: function() {
				console.log("---" + this.itemsId);
				this.$http.post(gover.saveApplyInfo, {
					regNumber: this.regNumber,
					regAddress: this.regAddress,
					companyName: this.companyName,
					regDate: this.regDate,
					regCapital: this.regCapital,
					address: this.address,
					applyId: this.applyId,
					cardNum: this.cardNum,
					cardType: this.cardType,
					companyTel: this.companyTel,
					contactName: this.contactName,
					mobile: this.mobile,
					userId: this.userId,
					businessId: this.businessId,
					userType: this.userType,
					name: this.name,
					itemsId: this.itemsId
				}, {
					emulateJSON: true
				}).then(function(result) {
					
					if(type!='gr'){
						if(validateContUserName()==false||validateContUserPhone()==false||validateContUserAddress()==false||validateLibertyName()==false||validateLibertyCode()==false||validateLibertyAddress()==false||validateRegDate()==false||validateRegFund()==false||validateContPhone()==false){
							return false;
						}						
					}else{
						if(validateContUserName2()==false||validateContUserPhone2()==false||validateContUserAddress2()==false){
							return false;
						}
					}
					doMask();
					if(result.data.success) {
						unMask();
						window.location = "selfHelpAttachment.html?applyId=" + result.data.data.applyId;
					} else {
						unMask();
						showRedMsg("message", "服务器正忙,请稍候重试");
						console.log(result.message);
					}
				}, function() {
						unMask();
						showRedMsg("message", "服务器正忙,请稍候重试");
				})
			}
		},
		ready: function() {
			//初始化获得总页面数和列表数据
			if(userType == 'gr') {
				$("#type1").removeClass("dis_no");
			} else {
				$("#type2").removeClass("dis_no");
			}
			this.getApplyInfo();
		}
	});

});